package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.navigator.RestServiceDetail;

import javax.swing.text.BadLocationException;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class SearchKeyListener implements KeyListener {
    private RestServiceDetail restServiceDetail;

    public SearchKeyListener(RestServiceDetail restServiceDetail){

        this.restServiceDetail = restServiceDetail;
    }
    @Override
    public void keyTyped(KeyEvent e) {
    }

    @Override
    public void keyPressed(KeyEvent e) {
    }

    @Override
    public void keyReleased(KeyEvent e) {
        //回车直接搜索
        if (e.getKeyCode() == 10) {
            try {
                if (restServiceDetail.getSearchKey() != null && restServiceDetail.getResponseTextArea() != null) {
                    restServiceDetail.getResponseTextArea().search(restServiceDetail.getSearchKey());
                }
            } catch (BadLocationException var3) {
                var3.printStackTrace();
            }
        }
    }
}
